<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Get result from async query</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="mysqlnduhconnection.queryreadresultsetheader.html">MysqlndUhConnection::queryReadResultsetHeader</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="mysqlnduhconnection.refreshserver.html">MysqlndUhConnection::refreshServer</a></div>
 <div class="up"><a href="class.mysqlnduhconnection.html">MysqlndUhConnection</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="mysqlnduhconnection.reapquery" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">MysqlndUhConnection::reapQuery</h1>
  <p class="verinfo">(PECL mysqlnd-uh &gt;= 1.0.0-alpha)</p><p class="refpurpose"><span class="refname">MysqlndUhConnection::reapQuery</span> &mdash; <span class="dc-title">Get result from async query</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-mysqlnduhconnection.reapquery-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">bool</span> <span class="methodname"><strong>MysqlndUhConnection::reapQuery</strong></span>
    ( <span class="methodparam"><span class="type"><span class="type mysqlnd_connection">mysqlnd_connection</span></span> <code class="parameter">$connection</code></span>
   )</div>

  <p class="para rdfs-comment">
   Get result from async query.
  </p>
 </div>


<div class="refsect1 parameters" id="refsect1-mysqlnduhconnection.reapquery-parameters">
  <h3 class="title">参数</h3>
  <dl>

   
    <dt>
<em><code class="parameter">connection</code></em></dt>

    <dd>

     <p class="para">
      Mysqlnd connection handle. Do not modify!
     </p>
    </dd>

   
  </dl>

 </div>


 <div class="refsect1 returnvalues" id="refsect1-mysqlnduhconnection.reapquery-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns <strong><code>TRUE</code></strong> on success.
   Otherwise, returns <strong><code>FALSE</code></strong>
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-mysqlnduhconnection.reapquery-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-1879">
    <p><strong>Example #1 <span class="function"><strong>MysqlndUhConnection::reapQuery()</strong></span> example</strong></p>
        <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">class&nbsp;</span><span style="color: #0000BB">proxy&nbsp;</span><span style="color: #007700">extends&nbsp;</span><span style="color: #0000BB">MysqlndUhConnection&nbsp;</span><span style="color: #007700">{<br />&nbsp;public&nbsp;function&nbsp;</span><span style="color: #0000BB">reapQuery</span><span style="color: #007700">(</span><span style="color: #0000BB">$res</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;</span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"%s(%s)\n"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">__METHOD__</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">var_export</span><span style="color: #007700">(</span><span style="color: #0000BB">func_get_args</span><span style="color: #007700">(),&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">));<br />&nbsp;&nbsp;</span><span style="color: #0000BB">$ret&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">parent</span><span style="color: #007700">::</span><span style="color: #0000BB">reapQuery</span><span style="color: #007700">(</span><span style="color: #0000BB">$res</span><span style="color: #007700">);<br />&nbsp;&nbsp;</span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"%s&nbsp;returns&nbsp;%s\n"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">__METHOD__</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">var_export</span><span style="color: #007700">(</span><span style="color: #0000BB">$ret</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">));<br />&nbsp;&nbsp;return&nbsp;</span><span style="color: #0000BB">$ret</span><span style="color: #007700">;<br />&nbsp;}<br />}<br /></span><span style="color: #0000BB">mysqlnd_uh_set_connection_proxy</span><span style="color: #007700">(new&nbsp;</span><span style="color: #0000BB">proxy</span><span style="color: #007700">());<br /><br /></span><span style="color: #0000BB">$conn1&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">mysqli</span><span style="color: #007700">(</span><span style="color: #DD0000">"localhost"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"root"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">""</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"test"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$conn2&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">mysqli</span><span style="color: #007700">(</span><span style="color: #DD0000">"localhost"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"root"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">""</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"test"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$conn1</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"SELECT&nbsp;1&nbsp;as&nbsp;'one',&nbsp;SLEEP(1)&nbsp;AS&nbsp;_sleep&nbsp;FROM&nbsp;DUAL"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">MYSQLI_ASYNC&nbsp;</span><span style="color: #007700">|&nbsp;&nbsp;</span><span style="color: #0000BB">MYSQLI_USE_RESULT</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$conn2</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"SELECT&nbsp;1.1&nbsp;as&nbsp;'one&nbsp;dot&nbsp;one'&nbsp;FROM&nbsp;DUAL"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">MYSQLI_ASYNC&nbsp;</span><span style="color: #007700">|&nbsp;&nbsp;</span><span style="color: #0000BB">MYSQLI_USE_RESULT</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$links&nbsp;</span><span style="color: #007700">=&nbsp;array(<br />&nbsp;</span><span style="color: #0000BB">$conn1</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">thread_id&nbsp;</span><span style="color: #007700">=&gt;&nbsp;array(</span><span style="color: #DD0000">'link'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">$conn1</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'processed'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">false</span><span style="color: #007700">),<br />&nbsp;</span><span style="color: #0000BB">$conn2</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">thread_id&nbsp;</span><span style="color: #007700">=&gt;&nbsp;array(</span><span style="color: #DD0000">'link'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">$conn2</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'processed'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">false</span><span style="color: #007700">)<br />);<br /><br /></span><span style="color: #0000BB">$saved_errors&nbsp;</span><span style="color: #007700">=&nbsp;array();<br />do&nbsp;{<br />&nbsp;</span><span style="color: #0000BB">$poll_links&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$poll_errors&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$poll_reject&nbsp;</span><span style="color: #007700">=&nbsp;array();<br />&nbsp;foreach&nbsp;(</span><span style="color: #0000BB">$links&nbsp;</span><span style="color: #007700">as&nbsp;</span><span style="color: #0000BB">$thread_id&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">$link</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;if&nbsp;(!</span><span style="color: #0000BB">$link</span><span style="color: #007700">[</span><span style="color: #DD0000">'processed'</span><span style="color: #007700">])&nbsp;{<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$poll_links</span><span style="color: #007700">[]&nbsp;=&nbsp;</span><span style="color: #0000BB">$link</span><span style="color: #007700">[</span><span style="color: #DD0000">'link'</span><span style="color: #007700">];<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$poll_errors</span><span style="color: #007700">[]&nbsp;=&nbsp;</span><span style="color: #0000BB">$link</span><span style="color: #007700">[</span><span style="color: #DD0000">'link'</span><span style="color: #007700">];<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$poll_reject</span><span style="color: #007700">[]&nbsp;=&nbsp;</span><span style="color: #0000BB">$link</span><span style="color: #007700">[</span><span style="color: #DD0000">'link'</span><span style="color: #007700">];<br />&nbsp;&nbsp;}<br />&nbsp;}<br />&nbsp;if&nbsp;(</span><span style="color: #0000BB">0&nbsp;</span><span style="color: #007700">==&nbsp;</span><span style="color: #0000BB">count</span><span style="color: #007700">(</span><span style="color: #0000BB">$poll_links</span><span style="color: #007700">))<br />&nbsp;&nbsp;break;<br /><br />&nbsp;if&nbsp;(</span><span style="color: #0000BB">0&nbsp;</span><span style="color: #007700">==&nbsp;(</span><span style="color: #0000BB">$num_ready&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mysqli_poll</span><span style="color: #007700">(</span><span style="color: #0000BB">$poll_links</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$poll_errors</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$poll_reject</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">200000</span><span style="color: #007700">)))<br />&nbsp;&nbsp;continue;<br /><br />&nbsp;if&nbsp;(!empty(</span><span style="color: #0000BB">$poll_errors</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;die(</span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$poll_errors</span><span style="color: #007700">));<br />&nbsp;}<br /><br />&nbsp;foreach&nbsp;(</span><span style="color: #0000BB">$poll_links&nbsp;</span><span style="color: #007700">as&nbsp;</span><span style="color: #0000BB">$link</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;</span><span style="color: #0000BB">$thread_id&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mysqli_thread_id</span><span style="color: #007700">(</span><span style="color: #0000BB">$link</span><span style="color: #007700">);<br />&nbsp;&nbsp;</span><span style="color: #0000BB">$links</span><span style="color: #007700">[</span><span style="color: #0000BB">$thread_id</span><span style="color: #007700">][</span><span style="color: #DD0000">'processed'</span><span style="color: #007700">]&nbsp;=&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">;<br /><br />&nbsp;&nbsp;if&nbsp;(</span><span style="color: #0000BB">is_object</span><span style="color: #007700">(</span><span style="color: #0000BB">$res&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mysqli_reap_async_query</span><span style="color: #007700">(</span><span style="color: #0000BB">$link</span><span style="color: #007700">)))&nbsp;{<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;result&nbsp;set&nbsp;object<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">while&nbsp;(</span><span style="color: #0000BB">$row&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mysqli_fetch_assoc</span><span style="color: #007700">(</span><span style="color: #0000BB">$res</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;eat&nbsp;up&nbsp;all&nbsp;results<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$row</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">mysqli_free_result</span><span style="color: #007700">(</span><span style="color: #0000BB">$res</span><span style="color: #007700">);<br />&nbsp;&nbsp;}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;either&nbsp;there&nbsp;is&nbsp;no&nbsp;result&nbsp;(no&nbsp;SELECT)&nbsp;or&nbsp;there&nbsp;is&nbsp;an&nbsp;error<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">if&nbsp;(</span><span style="color: #0000BB">mysqli_errno</span><span style="color: #007700">(</span><span style="color: #0000BB">$link</span><span style="color: #007700">)&nbsp;&gt;&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$saved_errors</span><span style="color: #007700">[</span><span style="color: #0000BB">$thread_id</span><span style="color: #007700">]&nbsp;=&nbsp;</span><span style="color: #0000BB">mysqli_errno</span><span style="color: #007700">(</span><span style="color: #0000BB">$link</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"'%s'&nbsp;caused&nbsp;%d\n"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$links</span><span style="color: #007700">[</span><span style="color: #0000BB">$thread_id</span><span style="color: #007700">][</span><span style="color: #DD0000">'query'</span><span style="color: #007700">],&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">mysqli_errno</span><span style="color: #007700">(</span><span style="color: #0000BB">$link</span><span style="color: #007700">));<br />&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;}<br />&nbsp;}<br />}&nbsp;while&nbsp;(</span><span style="color: #0000BB">true</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
proxy::reapQuery(array (
  0 =&gt; NULL,
))
proxy::reapQuery returns true
array(1) {
  [&quot;one dot one&quot;]=&gt;
  string(3) &quot;1.1&quot;
}
proxy::reapQuery(array (
  0 =&gt; NULL,
))
proxy::reapQuery returns true
array(2) {
  [&quot;one&quot;]=&gt;
  string(1) &quot;1&quot;
  [&quot;_sleep&quot;]=&gt;
  string(1) &quot;0&quot;
}
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-mysqlnduhconnection.reapquery-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member">
     <span class="function"><a href="function.mysqlnd-uh-set-connection-proxy.html" class="function" rel="rdfs-seeAlso">mysqlnd_uh_set_connection_proxy()</a> - Installs a proxy for mysqlnd connections</span>
    </li>
    <li class="member">
     <span class="function"><strong>mysqli_real_async_query()</strong></span>
    </li>
   </ul>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="mysqlnduhconnection.queryreadresultsetheader.html">MysqlndUhConnection::queryReadResultsetHeader</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="mysqlnduhconnection.refreshserver.html">MysqlndUhConnection::refreshServer</a></div>
 <div class="up"><a href="class.mysqlnduhconnection.html">MysqlndUhConnection</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
